namespace MockingBird.Common.Infrastructure.Logging
{
    using System;
    using System.Configuration;

    /// <summary>
    /// The central manager class for application tracing, through which all application tracing should be done.
    /// </summary>
    /// <remarks>
    /// This class instantiates any required trace listeners, and provides a means of getting access to a singleton
    /// instance of the <see cref="Microsoft.Sdc.BizTalkOM.SmartTrace"/> class through which all tracing
    /// is performed.
    /// </remarks>
    public sealed class TraceManager
    {
        private static SmartTrace smartTrace;
        private static string logPath = null;

        /// <summary>
        /// Has only static members so cannot be instantiated.
        /// </summary>
        private TraceManager()
        {
        }

        /// <summary>
        /// Initialises static members of the <see cref="Microsoft.Sdc.BizTalkOM.TraceManager"/>.
        /// </summary>
        static TraceManager()
        {
            smartTrace = new SmartTrace("MockingBird", "Provides Tracing for MockingBird Components", 8);
            string enableTracingFlag = ConfigurationManager.AppSettings["enable_tracing"];
            if (!String.IsNullOrEmpty(enableTracingFlag))
            {
                System.Diagnostics.Debug.WriteLine("Enable Tracing Flag is set to : " + enableTracingFlag);
                smartTrace.isTracingOn = Boolean.Parse(enableTracingFlag);
            }
            else
            {
                // We set it to ON always as this is vital for MockingBird
                smartTrace.isTracingOn = true;
            }
        }

        /// <summary>
        /// Return a singleton instance of the <see cref="Microsoft.Sdc.BizTalkOM.SmartTrace"/> object.
        /// </summary>
        public static SmartTrace SmartTrace
        {
            get
            {
                return smartTrace;
            }
        }
    }
}
